 var table ,form ,laypage ,layer ,element ,laydate ,upload;//时间组件
var check=true;
$(function(){ 
	var hid=getQueryString("id");
	var saveurl="/scrap/saveScrap.do";
	layui.use(['table','form','laypage','layer', 'element', 'laydate','upload'], function(){
		 table = layui.table;
		 form=layui.form;
		 laypage = layui.laypage ;//分页
		 layer = layui.layer ;//弹层
		 element = layui.element; //元素操作
		 laydate = layui.laydate; //时间组件 
		 upload = layui.upload;
    	 //表单验证
        form.verify({	  
        	fequipmentId: function(value, item)
	        {   //处理结果验证
				  if(validate.isBlank(value))
				  {
					 return "请填选择设备";
				  }
		      },
	         fremarks: function(value, item)
		     {    
	        	 if(validate.isBlank(value))
				  {
					 return "请填写报废原因";
				  }
		  		  if(!validate.isLength(value,1,300))
	  		      {
	  		         return '报废原因长度不能超过300个字符';
	  		      }
		  	   }
		  	          
       })
      form.on('submit(formDemo)', function(data){  
			this.blur();//防止点回车，按钮重复点击
			var loadIndex = layer.load(1);//显示加载层
			//判断时间为空值为null
			var requestData= formToJsonObj("form_edit", []);
			$.ajax({
				url:'/scrap/saveScrap.do',
				type:'POST',
				async:false,
				data:formatParam(requestData),
				timeout: 200000,
				headers: setHeader(),
				success:function(res){         //请求成功
		        	   if(res.status == 200) {  
		        		   layer.msg(res.resultMsg, {icon: res.icon},function(){
		   					     var index = parent.layer.getFrameIndex(window.name);
		   					      parent.layui.table.reload("tabledata")//
		   					      parent.layer.close(index);//关闭弹出的子页面窗口
		   					}); 					
		        	    }else if(res.status == 666){
		  					TIMEOUT(); 
		  		        }else{
		  					layer.msg(res.resultMsg, {icon: res.icon});		  					
		  				}  
		        	   layer.close(loadIndex);//关闭加载层
	              }		
			})
		  return false; //阻止表单跳转。
	  })
   }) 	
})